package com.songhq.disruptor;
 
import java.util.concurrent.CountDownLatch;
 
import com.lmax.disruptor.dsl.Disruptor;
//创建一个发送消费事件 的类，用于发送要处理的消息
public class TradeTransactionPublisher implements Runnable {
    Disruptor<TradeTransaction> disruptor;  
    private CountDownLatch latch;
    private static int LOOP=10;//生产者发送10条消息 
    
    public TradeTransactionPublisher(CountDownLatch latch,Disruptor<TradeTransaction> disruptor) {  
        this.disruptor=disruptor;  
        this.latch=latch;  
    }  
  
	@Override
	public void run() {
        for(int i=0;i<LOOP;i++){  
        	System.out.println("生产者成功向Ringbuffer中发送了一条消息");
        	TradeTransactionEventTranslator tradeTransloator=new TradeTransactionEventTranslator(new  TradeTransaction());  
            disruptor.publishEvent(tradeTransloator);  
        }  
        latch.countDown();  
    }  

}